apiVersion: monitoring.coreos.com/v1
kind: Alertmanager
metadata:
  labels:
    alertmanager: main
  name: main
  namespace: kubesphere-monitoring-system
spec:
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: alertmanager
              operator: In
              values:
              - main
          namespaces:
          - kubesphere-monitoring-system
          topologyKey: kubernetes.io/hostname
        weight: 100
  image: {{ alertmanager_repo }}:{{ alertmanager_tag }}
  resources:
    limits:
      cpu: {{ monitoring.alertmanager.limits.cpu | default("200m") }}
      memory: {{ monitoring.alertmanager.limits.memory | default("200Mi") }}
    requests:
      cpu: {{ monitoring.alertmanager.requests.cpu | default("20m") }}
      memory: {{ monitoring.alertmanager.requests.memory | default("30Mi") }}
  nodeSelector:
    kubernetes.io/os: linux

{% if nodeNum is defined and nodeNum < 3 %}
  replicas: {{ monitoring.alertmanagerReplicas | default(1) }}
{% else %}
  replicas: {{ monitoring.alertmanagerReplicas | default(3) }}
{% endif %}
  securityContext:
    fsGroup: 2000
    runAsNonRoot: true
    runAsUser: 1000
  serviceAccountName: alertmanager-main
  version: {{ alertmanager_tag }}
